﻿using OASystem.BLL.IService;
using OASystem.Common;
using OASystem.Model;
using OASystem.Models;
using OASystem.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace OASystem.Controllers
{
    public class RecodeController : Controller
    {
        #region 注入
        private IRecodeService _recodeService;
        public RecodeController(IRecodeService recodeService)
        {
            _recodeService = recodeService;
        }
        #endregion

        /// <summary>
        /// 显示列表
        /// </summary>
        /// <param name="name">当前用户登录名</param>
        /// <param name="oneer">执行人</param>
        /// <param name="TaskTiltle">任务标题</param>
        /// <param name="CompletionTime">发布时间</param>
        /// <returns></returns>
        public JsonResult Display(int page, int limit, string oneer, string TaskTiltle, string CompletionTime)
        {
            #region 实体
            ResponseResult result = new ResponseResult();
            PageListResult<Taskquery> a = new PageListResult<Taskquery>();
            #endregion
            //取出当前登录用户信息
            Userinfo userinfo = AdminContext.context.adminUser;
            //调用显示列表方法
            result = _recodeService.Display(userinfo.UserId, oneer, TaskTiltle, CompletionTime);
            #region 赋值
            #region 防止异常处理
            List<Taskquery> tq = null;
            if (result != null)
            { tq = result.data; }
            if (tq != null)
            { a.count = result.count; a.data = tq.Skip((page - 1) * limit).Take(limit).ToList(); }
            else
            { a.count = 0; a.data = null; }
            #endregion
            a.code = 0;
            a.msg = "";
            #endregion
            return Json(a, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="ID">所选行ID</param>
        /// <returns></returns>
        public JsonResult Delete(int ID)
        {
            ResponseResult result = new ResponseResult();
            result = _recodeService.Delete(ID);
            return Json(result);
        }

        /// <summary>
        /// 完成状态
        /// </summary>
        /// <param name="id">所选行ID</param>
        /// <param name="status">修改后的状态</param>
        /// <returns></returns>
        public JsonResult Update(int id, int status)
        {
            ResponseResult result = new ResponseResult();
            result = _recodeService.Updater(id, status);
            return Json(result);
        }

    }
}